package com.stox.ui.javafx.charting.model.plot;

import java.util.List;

import javafx.scene.canvas.Canvas;

import com.stox.model.AbstractModel;
import com.stox.model.preference.Preference;
import com.stox.ui.javafx.charting.model.enumeration.ChartType;
import com.stox.ui.javafx.charting.model.uiunit.AbstractPrimaryUiUnit;
import com.stox.ui.javafx.charting.strategy.Strategy;
import com.stox.ui.javafx.charting.widget.PrimaryChart;

public abstract class AbstractPrimaryPlot<T, 
						W extends PrimaryChart<U>,
						V extends AbstractPrimaryUiUnit<T,W, V, U>, 
						U extends AbstractPrimaryPlot<T,W,V,U>> 
		extends AbstractPlot<T, W, V, U> {

	private ChartType chartType = ChartType.HLC;

	protected double volumeSum = 0;

	private Strategy<V> backgroundColorStrategy;
	
	public AbstractPrimaryPlot(AbstractModel model) {
		super(model);
	}

	public abstract void setVolumeData();
	
	
	
	public void paintBackground() {
		if(getBackgroundColorStrategy() == null) {
			Canvas canvas = getChart().getCanvas();
			canvas.getGraphicsContext2D().setFill(Preference.instance.getChartingPreference().getDefaultBackgroundColor());
			canvas.getGraphicsContext2D().fillRect(canvas.getLayoutX(), canvas.getLayoutY(), canvas.getWidth(), canvas.getHeight());
		}else {
			for(int index = getChart().getChartingView().getEndIndex()-1; 
					index >= getChart().getChartingView().getStartIndex(); index--) {
				getUiUnits().get(index).paintBackground();
			}
		}
	}
	
	@Override
	public List<V> getUiUnits() {
		return super.getUiUnits();
	}
	
	@Override
	public void reset() {
		super.reset();
		volumeSum = 0;
	}
	
	public ChartType getChartType() {
		return chartType;
	}

	public void setChartType(ChartType chartType) {
		this.chartType = chartType;
	}

	public double getVolumeSum() {
		return volumeSum;
	}

	public Strategy<V> getBackgroundColorStrategy() {
		return backgroundColorStrategy;
	}

	public void setBackgroundColorStrategy(
			Strategy<V> backgroundColorStrategy) {
		this.backgroundColorStrategy = backgroundColorStrategy;
	}
	
}
